package com.liangzai.spring.demo.controller;

import com.liangzai.spring.demo.model.UserInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/resp")
@Controller
public class RespController {

    @RequestMapping("/r1")
    public String r1(){
        return "/aa/Index.html";
    }

    @RequestMapping("/r2")
    @ResponseBody
    public String r2(){
        return "我是前端需要的数据";
    }

    @RequestMapping("/r3")
    @ResponseBody
    public UserInfo r3(){
        UserInfo userInfo = new UserInfo("liangzai",1,20);
        return userInfo;
    }

    @RequestMapping("/r4")
    @ResponseBody
    public String setHeader(HttpServletResponse response){
        response.setHeader("myheader","myHeaher");
        return "Header设置成功!";
    }

    @RequestMapping("/r5")
    @ResponseBody
    public String setStatus(HttpServletResponse response){
        response.setStatus(401);
        return "状态码设置成功!";
    }

    @RequestMapping(value = "/r6",produces = "text/plain")
    @ResponseBody
    public String r6(){
        return "/aa/Index.html";
    }

    @RequestMapping("/r7")
    public String r7(){
        return "/aa/404.html";
    }


}
